/* (C) Copyright IBM Corp. 2010 */

package com.ibm.mining.sqldata;
import java.sql.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.List;

public class JazzItemChange {
	
	public Timestamp modified;
	public String modifiedBy;
	
	class PropertyChange {
		public String property;
		public String changeType;
		public String oldVal, newVal;
	}

	public String itemType;
	public Map<String, String> itemKeys;
	
	public Timestamp getModified() {
		return modified;
	}

	public void setModified(Timestamp modified) {
		this.modified = modified;
	}

	public String getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public String getItemType() {
		return itemType;
	}

	public void setItemType(String itemType) {
		this.itemType = itemType;
	}

	public Map<String, String> getItemKeys() {
		return itemKeys;
	}

	public void addItemKey(String key, String value) {
		itemKeys.put(key, value);
	}

	public List<PropertyChange> getPropertyChanges() {
		return propertyChanges;
	}
	
	public int numberOfPropertyChanges() {
		return propertyChanges.size();
	}

	public List<PropertyChange> propertyChanges;
	
	public JazzItemChange(String modifiedBy, Timestamp modified) {
		itemKeys = new HashMap<String, String>();
		propertyChanges = new LinkedList<PropertyChange>();
		this.modifiedBy = modifiedBy;
		this.modified = modified;
	}
	
	public void addChange(String property, String changeType, String oldVal, String newVal) {
		PropertyChange pc = new PropertyChange();
		pc.property = property;
		pc.changeType = changeType;
		pc.oldVal = oldVal;
		pc.newVal = newVal;
		propertyChanges.add(pc);
	}
	
	public String toString() {
		String s = "JazzItemChange for " + itemType + "\n";
		for (PropertyChange pc : propertyChanges) {
			s += "\tProperty Change:"
				+ "\n\t\tproperty: " + pc.property
				+ "\n\t\tchange type: " + pc.changeType
				+ "\n\t\told value: " + pc.oldVal
				+ "\n\t\tnew value: " + pc.newVal
				+ "\n";
		}
		return s;
		
	}
	
}
